package com.LC.Report;

import com.LC.Constant.MessageConstant;
import com.LC.Entity.PieData;
import com.LC.Entity.Result;
import com.LC.Service.MemberService;
import com.LC.Service.SetMealService;
import com.alibaba.dubbo.config.annotation.Reference;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/Report")
public class ReportController {
    
    @Reference
    private MemberService memberService;
    
    @Reference
    private SetMealService setMealService;
    
    @PreAuthorize("hasAuthority('REPORT_VIEW')")
    @RequestMapping("/MemberReport")
    public Result getMemberReport(){
        Map<String, Object> map = null;
        try {
            map = memberService.MemberCountPerMonths();
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(false,MessageConstant.GET_MEMBER_NUMBER_REPORT_FAIL);
        }
        return new Result(true, MessageConstant.GET_MEMBER_NUMBER_REPORT_SUCCESS,map);
    }

    @PreAuthorize("hasAuthority('REPORT_VIEW')")
    @RequestMapping("/SetMealReport")
    public Result getSetMealReport(){
        List<PieData> pieDataList = null;
        try {
            pieDataList = setMealService.setMealReport();
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(false,MessageConstant.GET_SETMEAL_COUNT_REPORT_FAIL);
        }
        return new Result(true,MessageConstant.GET_SETMEAL_COUNT_REPORT_SUCCESS,pieDataList);
    }
    
}
